/**
 * 视频相关操作
 * Created by zhangluxin on 2017/6/1.
 */
var AgoraUtil = {};

AgoraUtil.initVideoView = function (videoData) {
    if (window.inReview) {
        return;
    }
    AgoraUtil.visible_count = 0;
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "initVideoView:", videoData);
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "initVideoView", "(Ljava/lang/String;)V", videoData);
    }
};

AgoraUtil.openVideo = function (roomid, uid) {
    if (window.inReview) {
        return;
    }
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "openVideo:uid:", roomid, uid);
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "openVideo", "(Ljava/lang/String;Ljava/lang/String;)V", roomid, uid);
    }
};

AgoraUtil.hideAllVideo = function () {
    if (window.inReview) {
        return;
    }
    AgoraUtil.visible_count++;
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "hideAllVideo");
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "hideAllVideo", "()V");
    }
};

AgoraUtil.showAllVideo = function () {
    if (window.inReview) {
        return;
    }
    AgoraUtil.visible_count--;
    if (AgoraUtil.visible_count > 0) {
        return;
    }
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "showAllVideo");
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "showAllVideo", "()V");
    }
};

AgoraUtil.closeVideo = function () {
    if (window.inReview) {
        return;
    }
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "closeVideo");
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "closeVideo", "()V");
    }
};

AgoraUtil.changeViewSizeToScreenCenter = function (uid, x, y, width, height) {
    if (window.inReview) {
        return;
    }
    x = x || cc.director.getWinSize().width / 2;
    y = y || cc.director.getWinSize().height / 2;
    width = width || 300;
    height = height || 300;
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "changeViewSizeToScreenCenter:x:y:width:height:", uid + '', x + '', y + '', width + '', height + '');
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "changeViewSizeToScreenCenter",
            "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V"
            , uid + '', parseInt(x) + '', parseInt(y) + '', parseInt(width) + '', parseInt(height) + '');
    }
};

AgoraUtil.changeViewSizeToNormal = function (uid) {
    if (window.inReview) {
        return;
    }
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "changeViewSizeToNormal:", uid + '');
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "changeViewSizeToNormal", "(Ljava/lang/String;)V", uid + '');
    }
};

AgoraUtil.changeViewSizeToNormal = function (uid) {
    if (window.inReview) {
        return;
    }
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "changeViewSizeToNormal:", uid + '');
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "changeViewSizeToNormal", "(Ljava/lang/String;)V", uid + '');
    }
};

AgoraUtil.muteRemoteVideoStream = function (uid, mute) {
    if (window.inReview) {
        return;
    }
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "muteRemoteVideoStream:val:", uid + '', mute);
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "muteRemoteVideoStream", "(Ljava/lang/String;Z)V", uid + '', mute);
    }
};

AgoraUtil.muteRemoteAudioStream = function (uid, mute) {
    if (window.inReview) {
        return;
    }
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "muteRemoteAudioStream:val:", uid + '', mute);
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "muteRemoteAudioStream", "(Ljava/lang/String;Z)V", uid + '', mute);
    }
};

AgoraUtil.muteLocalVideoStream = function (mute) {
    if (window.inReview) {
        return;
    }
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "muteLocalVideoStream:", mute);
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "muteLocalVideoStream", "(Z)V", mute);
    }
};

AgoraUtil.muteLocalAudioStream = function (mute) {
    if (window.inReview) {
        return;
    }
    if (cc.sys.os == cc.sys.OS_IOS) {
        jsb.reflection.callStaticMethod("AgoraUtil", "muteLocalAudioStream:", mute);
    } else if (cc.sys.os == cc.sys.OS_ANDROID) {
        jsb.reflection.callStaticMethod(packageUri + "/utils/AgoraUtil", "muteLocalAudioStream", "(Z)V", mute);
    }
};

AgoraUtil.visible_count = 0;